
const app = getApp();
var http = require('../../../../service/http.js');
var util = require('../../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    discountCardList:[],//优惠券
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getDiscountCard();
  },
  getDiscountCard: function () {//获取优惠券
    app.getDiscountCard();
    console.log(app.data.discountCardList);
    let getDiscountCardTask = setInterval(()=>{
      let discountCardList = app.data.discountCardList;
      if (discountCardList.length > 0){
        clearInterval(getDiscountCardTask);
        this.setData({
          discountCardList: app.data.discountCardList
        })
      }
    },200)
  
  },
  selectProductById: function (e) {//根据商品id 查商品详情
    console.log('根据商品id 查商品详情参数');
    console.log(e);

    this.setData({
      productId: e.currentTarget.dataset.productid,
      pageUrl: '/pages/product/product'
    })
    // app.selectProductById(this);
    util.throttle(app.selectProductById, 500, this);
  },
  getFormId: function (e) {
    console.log(e);
    app.getFormId(e);
  },
  /**
   * 没有商品id 回到首页
   */
  backToHome:function(){
    app.backToHome();
  }
  
})